package com.huike.web.controller.notice;

import com.huike.clues.domain.SysNotice;
import com.huike.clues.domain.result.SysNoticePageResult;
import com.huike.clues.service.NoticeService;
import com.huike.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description noticeController
 * @Author bin
 * @Date 2023-10-15
 */
@RestController
@RequestMapping("/system/notice")
@Slf4j
@Api(tags = "通知公告相关接口")
@RequiredArgsConstructor
public class NoticeController {

    private final NoticeService noticeService;


    /**
     * 处理获取系统提醒下拉列表
     * 返回的是AjaxResult<List<SysNotice>>
     * @param status
     * @return
     */
    @ApiOperation("处理获取系统提醒下拉列表接口")
    @GetMapping("/list/{status}")
    public AjaxResult list(@PathVariable Integer status){

        log.info("开始执行处理获取系统提醒下拉列表接口：{}",status);

        List<SysNotice> sysNoticeList = noticeService.list(status);

        return AjaxResult.success(sysNoticeList);


    }



    /**
     * 处理获取系统提醒分页列表
     * @param status
     * @return
     */
    @ApiOperation("处理获取系统提醒分页列表接口")
    @GetMapping("/pagelist/{status}")
    public SysNoticePageResult pagelist(@PathVariable Integer status){

        // System.out.println(status);
        log.info("开始执行处理获取系统提醒分页列表接口：{}",status);

        // 手动拼接反回数据
        SysNoticePageResult sysNoticePageResult = noticeService.pagelist(status);

        if (sysNoticePageResult != null){
            AjaxResult success = AjaxResult.success();
            BeanUtils.copyProperties(success,sysNoticePageResult);
            return sysNoticePageResult;
        }else {
            AjaxResult success = AjaxResult.error();
            BeanUtils.copyProperties(success,sysNoticePageResult);
            return sysNoticePageResult;
        }



    }



    /**
     * 获取详情信息
     * 返回的是
     * @param noticeId
     * @return
     */
    @ApiOperation("获取详情信息接口")
    @GetMapping ("/{noticeId}")
    public AjaxResult<SysNotice> noticeId(@PathVariable Integer noticeId){

        log.info("开始执行获取详情信息接口：{}",noticeId);

        SysNotice sysNotice = noticeService.noticeId(noticeId);

        return AjaxResult.success(sysNotice);


    }



    /**
     * 未读变已读
     * 返回的是
     * @param noticeId
     * @return
     */
    @ApiOperation("获取详情信息接口")
    @PutMapping("/{noticeId}")
    public AjaxResult updateNoticeId(@PathVariable Integer noticeId){

        log.info("开始执行获取详情信息接口：{}",noticeId);

        noticeService.updateNoticeId(noticeId);

        return AjaxResult.success();


    }





}
